Skip to content

Update $effect and testing docs to mention issues with push on state array #16247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

raythurnvoid
Copy link
Contributor

@raythurnvoid raythurnvoid commented Jun 26, 2025

Should prevent misunderstandings like #16092

This PR clarifies in the testing documentation that testing examples should not use $state for arrays that are mutated. It also adds a separate untrack section in the $effect documentation to warn users about updating $state values while depending on those same values within an effect.

This should help clarify common misunderstandings users have when dealing with $state versus regular variables.

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.
  • If this PR changes code within packages/svelte/src, add a changeset (npx changeset).

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

@svelte-docs-bot
Copy link

Copy link
Contributor

Playground

pnpm add https://pkg.pr.new/svelte@16247

@Rich-Harris
Copy link
Member

Thank you. I'm averse to having 'side-quests' in the docs, so I got to thinking about how we can make this situation more self-explanatory, and #16405 is what I came up with — it tightens up the error message to make it clear that it's happening because an effect reads and writes the same piece of state, logs the site of that state change to eliminate any guesswork, and fleshes out the docs page that the error message links to. As such I'll close this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants